define([
		'jquery',
		'Views/loginView',
		'Views/joinView',
		'Views/updateView',
		'Models/User'
		
], function ($, LoginView, JoinView, UpdateView, User){



		
	var MemberController = function(ajaxController, mainControll) {
		
		this.ajaxController = ajaxController;
		this.mainController = mainControll;
		
	};	
	var loginView = new LoginView();
	var joinView = new JoinView();
	var updateView = new UpdateView();
	var user = new User();
	
	MemberController.prototype = {
			
			drawing : function(action, res, user) {
				var _this = this;
				if(action == "login") {
					
					loginView.drawing();
					loginView.setLoginEvent(function() {    //로그인 버튼
						
						_this.login();
	
					});
					loginView.setJoinEvent(function() {    //회원가입 폼 버튼
						_this.mainController.router("join");
					});
					
				}else if(action == "join") {
					
					joinView.drawing();
					joinView.setCancelEvent(function() {    //취소 버튼
						_this.mainController.router("login");
					});
					joinView.setJoinEvent(function() {    //회원가입 버튼
						
						_this.join();
					});
					
					
				}else if(action == "update") {
					
					updateView.drawing(user,res);
					updateView.setUpdateEvent(function() {    //회원정보 수정 버튼
						
						_this.update();
				
					});
					updateView.setCancelEvent(function() {    //취소 버튼
						
						_this.mainController.router("memo",res);
						
					});
					
					
				}
				
				
					
					
			},
			
		join : function() {
			var $id =  $('#id').val();
			var $age =  $('#age').val();
			var $name =  $('#name').val();
			var $pass1 =  $('#password1').val();
			var $pass2 =  $('#password2').val();
			
			if($id == "" || $name == "" || $pass1 == "" || $pass2 == "") {
				alert("빈 칸을 채워주세요!");
				return false;
			}
			var cc =true;
			var id = $id;
			for(var i = 0; i <$id.length; i++) {
				
				if((id.charAt(i) >='0' && id.charAt(i) <= '9') || (id.charAt(i) >='a' && id.charAt(i) <='z') || (id.charAt(i) >='A' && id.charAt(i) <= 'Z')) {
					cc = true;
				}else {
					cc =false;
					break;
				}
			}
			if(cc == false) {
				alert("아이디에는 특수문자가 금지됩니다.");
				return false;
			}
			if(isNaN($age)|| $age == "") {
				alert("나이는 숫자만 입력하세요.");
				return false;
			}
				var params = "&id="+$id+"&age="+$age+"&name="+$name+"&password1="+$pass1+"&password2="+$pass2;
				this.ajaxController.contact("POST","./join.do",params);
				
		},
		login : function() {
			
		
			var $id =  $('#id').val();
			var $pass =  $('#password').val();
			
			if($id == "" || $pass == "") {
				alert("빈 칸을 채워주세요!");
				return false;
			}
				var params = "id="+$id+"&password="+$pass;
				this.ajaxController.contact("POST","./login.do",params);
		},
		update : function() {
			var $age =  $('#age').val();
			var $pass1 =  $('#password1').val();
			var $pass2 =  $('#password2').val();
			
			if($pass1 == "" || $pass2 == "") {
				alert("빈 칸을 채워주세요!");
				return false;
			}
			if($age == "" || isNaN($age)) {
				alert("나이는 숫자만 입력하세요.");
				return false;
			}
				var params = "&age="+$age+"&password1="+$pass1+"&password2="+$pass2;
				this.ajaxController.contact("POST","./update.do",params);
		},
		getInfo : function() {
			
			this.ajaxController.getData("GET","./getInfo.do",null, null, "user");
			
			console.log("getInfo에서의 this");
			console.log(this);
		}
	};
		return MemberController;
});